package Text_47;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class Code {

	public static void main(String[] args) {
		 ArrayList<Student> list = new ArrayList<Student>();
	        Student s1 = new Student("202401",new Random().nextInt(3)+1,new Random().nextInt(99)+1);
	        Student s2 = new Student("202402",new Random().nextInt(3)+1,new Random().nextInt(99)+1);
	        Student s3 = new Student("202403",new Random().nextInt(3)+1,new Random().nextInt(99)+1);
	        Student s4 = new Student("202404",new Random().nextInt(3)+1,new Random().nextInt(99)+1);
	        Student s5 = new Student("202405",new Random().nextInt(3)+1,new Random().nextInt(99)+1);
	        list.add(s1);
	        list.add(s2);
	        list.add(s3);
	        list.add(s4);
	        list.add(s5);
	        for(Student i: list){
	            if(i.getScore()==3){
	                System.out.println(i);
	            }
	        }
	        //按score升序排列
	        Collections.sort(list);
	            for (Student s : list) {
	                System.out.println(s);
	            }
	    }
	}
	class Student implements Comparable<Student> {
	    /*学号：number(String)
	    年级：state(int)
	    成绩：score(int)*/
	    private String number;
	    private int state;
	    private int score;

	    public Student() {
	    }

	    public Student(String number, int state, int score) {
	        this.number = number;
	        this.state = state;
	        this.score = score;
	    }


	    public String getNumber() {
	        return number;
	    }


	    public void setNumber(String number) {
	        this.number = number;
	    }

	    public int getState() {
	        return state;
	    }

	    public void setState(int state) {
	        this.state = state;
	    }

	    public int getScore() {
	        return score;
	    }


	    public void setScore(int score) {
	        this.score = score;
	    }

	    public String toString() {
	        return "Student{" +
	                                "number='" + number + '\'' +
	                                ", state=" + state +
	                                ", score=" + score +
	                                '}';
	    }

	    @Override
	    public int compareTo(Student other) {
	        return Integer.compare(this.score, other.score);

	}

}
